from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class RegisterPage:
    def __init__(self, driver):
        self.driver = driver
        self.url = 'http://your-ecommerce-app/register'
        self.username_input = (By.ID, 'username')
        self.password_input = (By.ID, 'password')
        self.confirm_password_input = (By.ID, 'confirm-password')
        self.email_input = (By.ID, 'email')
        self.register_button = (By.ID, 'register-button')
    
    def navigate(self):
        self.driver.get(self.url)
    
    def enter_username(self, username):
        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(self.username_input)).send_keys(username)
    
    def enter_password(self, password):
        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(self.password_input)).send_keys(password)
    
    def enter_confirm_password(self, confirm_password):
        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(self.confirm_password_input)).send_keys(confirm_password)
    
    def enter_email(self, email):
        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(self.email_input)).send_keys(email)
    
    def click_register_button(self):
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(self.register_button)).click()
    
    def is_user_registered(self):
        # 假设成功注册后会跳转到另一个页面，这里只是示例
        return 'registration-success' in self.driver.current_url
    
    def get_error_message(self):
        # 假设错误消息在一个特定的元素中
        error_message_element = (By.ID, 'error-message')
        return WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(error_message_element)).text